# calculator.py

class Operation:
    def __init__(self):
        self.numberA = 0
        self.numberB = 0

    def get_numberA(self):
        return self.numberA

    def set_numberA(self, numberA):
        self.numberA = numberA

    def get_numberB(self):
        return self.numberB

    def set_numberB(self, numberB):
        self.numberB = numberB

    def get_result(self):
        raise NotImplementedError("Subclasses should implement this!")


class OperationAdd(Operation):
    def get_result(self):
        return self.numberA + self.numberB


class OperationSub(Operation):
    def get_result(self):
        return self.numberA - self.numberB


class OperationMul(Operation):
    def get_result(self):
        return self.numberA * self.numberB


class OperationDiv(Operation):
    def get_result(self):
        try:
            if self.numberB == 0:
                raise ValueError("除数不能为0！！！")
            return self.numberA / self.numberB
        except ValueError as e:
            print(e)
            return float('nan')  # 或者返回其他表示错误的值，如0，但NaN更合适表示未定义的结果


class OperationFactory:
    @staticmethod
    def create_operation(operate):
        if operate == '+':
            return OperationAdd()
        elif operate == '-':
            return OperationSub()
        elif operate == '*':
            return OperationMul()
        elif operate == '/':
            return OperationDiv()
        else:
            raise ValueError("无效的操作符")


def main():
    oper = OperationFactory.create_operation('+')
    oper.set_numberA(100)
    oper.set_numberB(20)
    result = oper.get_result()
    print(result)


if __name__ == "__main__":
    main()